﻿#region using...
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
#endregion

namespace Infusion.Silverlight.Controls.Ribbon
{
    #region : RibbonMainMenuPinableItem :
    #region Template Parts...
    [TemplatePart(Name = RibbonMainMenuPinableItem.RibbonMainMenuPinableItemLayoutRoot, Type = typeof(Grid))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.CanvasBorder, Type = typeof(Canvas))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.ClipBorder, Type = typeof(RectangleGeometry))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.CanvasBackground, Type = typeof(Canvas))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.ClipBackground, Type = typeof(RectangleGeometry))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.GridText, Type = typeof(Grid))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.TxtNumber, Type = typeof(TextBlock))]
    [TemplatePart(Name = RibbonMainMenuPinableItem.TxtText, Type = typeof(TextBlock))]
    #endregion
    public class RibbonMainMenuPinableItem : Control
    {
        #region TemplatePart Names...
        public const string RibbonMainMenuPinableItemLayoutRoot = "RibbonMainMenuPinableItemLayoutRoot";
        public const string CanvasBorder = "CanvasBorder";
        public const string ClipBorder = "ClipBorder";
        public const string CanvasBackground = "CanvasBackground";
        public const string ClipBackground = "ClipBackground";
        public const string GridText = "GridText";
        public const string TxtNumber = "TxtNumber";
        public const string TxtText = "TxtText";
        #endregion

        #region TemplatePart Variables...
        private Grid ribbonMainMenuPinableItemLayoutRoot;
        private Canvas canvasBorder;
        private RectangleGeometry clipBorder;
        private Canvas canvasBackground;
        private RectangleGeometry clipBackground;
        private Grid gridText;
        private TextBlock txtNumber;
        private TextBlock txtText;
        #endregion

        #region Class Variables...
        private bool templateApplied = false;
        #endregion

        #region Dependency Properties...
        #region TextProperty
        /// <summary>
        /// Identifies the Infusion.Silverlight.Controls.Ribbon.RibbonMainMenuPinableItem.Label dependency property.
        /// </summary>
        public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
                "Label",
                typeof(string),
                typeof(RibbonMainMenuPinableItem),
                new PropertyMetadata(new PropertyChangedCallback(LabelPropertyChanged)));
        #endregion
        #endregion

        #region Dependency Property Changed Handlers...
        #region LabelPropertyChanged
        private static void LabelPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
        }
        #endregion
        #endregion

        #region Constructor(s)...
        #region RibbonMainMenuPinableItem
        public RibbonMainMenuPinableItem()
        {
            DefaultStyleKey = typeof(RibbonMainMenuPinableItem);
        }
        #endregion
        #endregion

        #region Methods...
        #region OnApplyTemplate
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!templateApplied)
            {
                ribbonMainMenuPinableItemLayoutRoot = (Grid)GetTemplateChild(RibbonMainMenuPinableItemLayoutRoot);
                canvasBorder = (Canvas)GetTemplateChild(CanvasBorder);
                clipBorder = (RectangleGeometry)GetTemplateChild(ClipBorder);
                canvasBackground = (Canvas)GetTemplateChild(CanvasBackground);
                clipBackground = (RectangleGeometry)GetTemplateChild(ClipBackground);
                gridText = (Grid)GetTemplateChild(GridText);
                txtNumber = (TextBlock)GetTemplateChild(TxtNumber);
                txtText = (TextBlock)GetTemplateChild(TxtText);

                if (!string.IsNullOrEmpty(Label))
                    txtText.Text = Label;

                templateApplied = true;
            }
        }
        #endregion
        #endregion

        #region Properties...
        #region Label
        public string Label
        {
            get { return (string)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }
        #endregion
        #endregion
    }
    #endregion
}